package com.cdh.oa.generator;


import com.cdh.oa.entity.*;
import com.cdh.oa.service.*;
import com.cdh.oa.util.MD5Util;
import com.cdh.oa.util.PinYinUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class InitTableData {

    @Autowired
    private IUserService userService;
    @Autowired
    private IDeptService deptService;
    @Autowired
    private IJobService jobService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IBtnService btnService;
    @Autowired
    private IRoleMenuBtnService roleMenuBtnService;

    //初始化部门
    @Test
    public void initDept(){
        Dept dept = new Dept();
        dept.setName("集团总部");
        dept.setLoc("重庆市沙坪坝区");
        dept.setLevel(0);
        System.out.println("测试部门添加状态："+deptService.save(dept));
    }

    //岗位初始化
    @Test
    public void initJob(){
        Job job = new Job();
        job.setName("管理员");
        job.setDeptId(1);
        System.out.println("岗位添加状态："+jobService.save(job));
    }

    //角色初始化
    @Test
    public void initRole(){
        Role role = new Role();
        role.setName("管理员");
        role.setCode("admin");
        System.out.println("角色添加状态："+roleService.save(role));
    }

    //初始化系统管理员
    @Test
    public void initUser(){
        User user = new User();
        user.setRelName("管理员");
        user.setPwd(MD5Util.getMD5("admin"));
        user.setName(PinYinUtil.getPingYin(user.getRelName()));
        user.setRoleId(1);
        user.setDeptId(1);
        user.setJob(1);
        System.out.println("系统管理员添加状态："+ userService.save(user));
    }


    @Test
    public void initMenu(){
        List<Menu> list = new ArrayList<>();
        Menu menu1 = new Menu("系统设置","",true,"",0);
        Menu menu11 = new Menu("人员信息管理","",false,"/user/index",1);
        Menu menu12 = new Menu("部门信息管理","",false,"/dept/index",1);
        Menu menu13 = new Menu("职位信息管理","",false,"/job/index",1);
        Menu menu14 = new Menu("权限管理","",false,"/role/index",1);
        Menu menu15 = new Menu("重置密码","",false,"/user/pwdRest",1);
        list.add(menu1);
        list.add(menu11);
        list.add(menu12);
        list.add(menu13);
        list.add(menu14);
        list.add(menu15);
        Menu menu2 = new Menu("办公模块","",false,"",0);
        Menu menu21 = new Menu("公告管理","",false,"/notice/index",7);
        Menu menu22 = new Menu("报销管理","",false,"/apply/index",7);
        Menu menu23 = new Menu("请假管理", "", false, "/leave/index", 7);
        list.add(menu2);
        list.add(menu21);
        list.add(menu22);
        list.add(menu23);
        Menu menu3 = new Menu("个人信息","",false,"/user/info",0);
        list.add(menu3);
        System.out.println("菜单初始化状态："+menuService.saveBatch(list));
    }

    //权限初始化
    @Test
    public void initBtn(){

        Btn btn1 = new Btn("添加","layui-btn layui-btn-normal add_btn","","");
        Btn btn2 = new Btn("删除","layui-btn layui-btn-danger del_btn","","");
        Btn btn3 = new Btn("编辑","layui-btn layui-btn-warm edit_btn","","");
        List<Btn> list = Arrays.asList(btn1,btn2,btn3);
        System.out.println("按钮初始状态："+btnService.saveBatch(list));
    }

    //角色菜单初始化
    @Test
    public void roleAndMenu(){
        RoleMenuBtn rmb1 = new RoleMenuBtn(1,1,1);
        RoleMenuBtn rmb2 = new RoleMenuBtn(1,2,1);
        RoleMenuBtn rmb3 = new RoleMenuBtn(1,2,2);
        RoleMenuBtn rmb4 = new RoleMenuBtn(1,2,3);
        RoleMenuBtn rmb5 = new RoleMenuBtn(1,3,1);
        RoleMenuBtn rmb6 = new RoleMenuBtn(1,4,1);
        RoleMenuBtn rmb7 = new RoleMenuBtn(1,5,1);
        RoleMenuBtn rmb8 = new RoleMenuBtn(1,6,1);
        RoleMenuBtn rmb9 = new RoleMenuBtn(1,7,1);
        RoleMenuBtn rmb10 = new RoleMenuBtn(1,8,1);
        RoleMenuBtn rmb11 = new RoleMenuBtn(1,9,1);
        RoleMenuBtn rmb12 = new RoleMenuBtn(1,10,1);
        RoleMenuBtn rmb13 = new RoleMenuBtn(1,11,1);

        List<RoleMenuBtn> list = Arrays.asList(rmb1, rmb2, rmb3, rmb4, rmb5, rmb6, rmb7, rmb8, rmb9, rmb10, rmb11, rmb12, rmb13);
        System.out.println("角色菜单关系表状态："+roleMenuBtnService.saveBatch(list));
    }

}
